import 'package:flutter/cupertino.dart';

class PhysicalShapeClipper extends CustomClipper<Path> {
  final bool isMe;

  final double radius;

  final double nipSize;

  final double offset;

  PhysicalShapeClipper(
      {this.isMe = true, this.radius = 4, this.nipSize = 8, this.offset = 10});

  @override
  Path getClip(Size size) {
    var path = Path();

    if (isMe) {
      path.addRRect(
        RRect.fromLTRBR(
          0,
          0,
          size.width - nipSize,
          size.height,
          Radius.circular(radius),
        ),
      );

      var path2 = Path();
      path2.lineTo(nipSize, nipSize);
      path2.lineTo(0, 2 * nipSize);
      path2.lineTo(0, 0);

      path.addPath(
        path2,
        Offset(size.width - nipSize, offset + 2 * nipSize),
      );
    } else {
      path.addRRect(
        RRect.fromLTRBR(
          nipSize,
          0,
          size.width - nipSize,
          size.height,
          Radius.circular(radius),
        ),
      );

      var path2 = Path();
      path2.lineTo(0, 2 * nipSize);
      path2.lineTo(-nipSize, nipSize);
      path2.lineTo(0, 0);

      path.addPath(path2, Offset(nipSize, offset + 2 * nipSize));
    }

    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return this != oldClipper;
  }
}
